import time
# 计算器程序
def add(x, y):
    return x + y

def subtract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    return x / y

run = True
while run:
    # 获取用户输入
    opertor = ['+', '-', '*', '/']
    num1 = float(input("请输入第一个数字："))
    choice = input("请输入运算方式 '+-*/'：")
    if choice not in opertor:
        print("输入错误，请重新输入有效的选择'+-*/'")
        continue
    num2 = float(input("请输入第二个数字："))

    if choice == '+':
        print(num1, "+", num2, "=", add(num1, num2))  
    elif choice == '-':
        print(num1, "-", num2, "=", subtract(num1, num2))   
    elif choice == '*':
        print(num1, "*", num2, "=", multiply(num1, num2))
    elif choice == '/':
        print(num1, "/", num2, "=", divide(num1, num2))
    # else:
    #     print("输入错误，请输入有效的选择！")

    time.sleep(2)
    r = input('输入Y退出，其他则继续使用')
    if r.lower() == "y":
        run = False